package angles

import "math"

func Deg2Rad(degree float64) float64 {
	return degree * math.Pi / 180.0
}

func Rad2Deg(rad float64) float64 {
	return rad * 180.0 / math.Pi
}

//NormalizeAnglePositive 将角度标准化为[0,2pi],返回弧度
func NormalizeAnglePositive(angle float64) float64 {
	result := math.Mod(angle, 2.0*math.Pi)
	if result < 0.0 {
		return result + 2*math.Pi
	}
	return result
}

//NormalizeAngle 将角度标准化为[-pi,pi],返回弧度
func NormalizeAngle(angle float64) float64 {
	result := math.Mod(angle+math.Pi, 2.0*math.Pi)
	if result <= 0.0 {
		return result + math.Pi
	}
	return result - math.Pi
}

//ShortestAngularDistance 返回输入的两个角度的最短距离，from，to为弧度,返回值范围-pi <= result <= pi,逆时针为正
func ShortestAngularDistance(from, to float64) float64 {
	return NormalizeAngle(to - from)
}
